package admincow.servlet.vaca;

import java.io.IOException;
import java.util.Collection;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import admincow.dao.VacaDAO;
import admincow.vo.VacaVO;

/**
 * Servlet implementation class for Servlet: UsuarioBuscarServlet
 * 
 */
public class VacaBuscarServlet extends javax.servlet.http.HttpServlet
		implements javax.servlet.Servlet {
	static final long serialVersionUID = 1L;

	/*
	 * (non-Java-doc)
	 * 
	 * @see javax.servlet.http.HttpServlet#HttpServlet()
	 */
	public VacaBuscarServlet() {
		super();
	}

	/*
	 * (non-Java-doc)
	 * 
	 * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request,
	 *      HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/*
	 * (non-Java-doc)
	 * 
	 * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request,
	 *      HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		System.out.println("VacaBuscarServlet");
		String x = request.getParameter("nombre");
		System.out.println(x);
		System.out.println("dentro del servlet buscar=== "+ x + "xxxxxxxxxxxxx");
		VacaDAO dao = new VacaDAO();
		Collection<VacaVO> y = dao.buscarPorNombre(x);

		// Guardar arreglo en ambiente request
		request.setAttribute("arreglo", y);

		// Hacer forward a jsp (cooperacion)
		RequestDispatcher rd = request
				.getRequestDispatcher("/vacaBuscar.jsp");
		rd.forward(request, response);

	}

}